package com.ugoodtech.mdcc.core.repository;

import com.ugoodtech.mdcc.core.domain.StationRegularServiceReport;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StationRegularServiceReportRepository extends PagingAndSortingRepository<StationRegularServiceReport, Long>
        , QueryDslPredicateExecutor<StationRegularServiceReport> {

    @Query("select count(id) from StationRegularServiceReport where answer_id=:answer_id and report_id=:report_id and question_id=156")
    Object count(@Param("answer_id") Long answer_id, @Param("report_id") Long report_id);

    @Query("select answerOther from StationRegularServiceReport where answer_id=:answer_id and report_id=:report_id ")
    List<Object> selectOther(@Param("answer_id") Long answer_id, @Param("report_id") Long report_id);

    @Query("from StationRegularServiceReport where answer_id=:answer_id and report_id=:report_id")
    Object isNull(@Param("answer_id") Long answer_id, @Param("report_id") Long report_id);

    @Query("from StationRegularServiceReport where report_id=:report_id and question_id=:question_id")
    StationRegularServiceReport selectQuestion(@Param("report_id") Long report_id, @Param("question_id") Long question_id);

    @Query("from StationRegularServiceReport where report_id=:report_id and question_id=:question_id and deleted=false and enabled=true")
    StationRegularServiceReport selectQuestionOther(@Param("report_id") Long report_id, @Param("question_id") Long question_id);
    @Query("from StationRegularServiceReport where report_id in :report_id and "
        + "question_id=:question_id and deleted=false and enabled=true")
    List<StationRegularServiceReport> selectQuestionOther(@Param("report_id") List<Long> report_id,
        @Param("question_id") Long question_id);
    @Query("from StationRegularServiceReport where report_id in :report_id and "
        + "question_id in :question_id and deleted=false and enabled=true")
    List<StationRegularServiceReport> selectQuestionOther(@Param("report_id") List<Long> report_id,
        @Param("question_id") List<Long> question_id);

    @Query("from StationRegularServiceReport where report_id=:report_id and answer_id=:answer_id and deleted=false and enabled=true")
    StationRegularServiceReport selectAnswer(@Param("report_id") Long report_id, @Param("answer_id") Long answer_id);

    @Query("from StationRegularServiceReport where report_id in :report_id and "
        + "answer_id=:answer_id and deleted=false and enabled=true")
    List<StationRegularServiceReport> selectAnswerOfReports(@Param("report_id") List<Long> report_id,
        @Param(
        "answer_id") Long answer_id);

    @Query("from StationRegularServiceReport where report_id=:report_id")
    List<StationRegularServiceReport> selectAnswer(@Param("report_id") Long report_id);

    @Query("select reportId from StationRegularServiceReport where answer_id=:answerId")
    Long[] selectReportId(@Param("answerId") Long answerId);

    @Query("from StationRegularServiceReport where report_id=:report_id and answer_id!=:answer_id")
    StationRegularServiceReport selectAnswerNe(@Param("report_id") Long report_id, @Param("answer_id") Long answer_id);


}


